﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace CNPC
{
    /// <summary>
    /// Summary description for NameService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class NameService : System.Web.Services.WebService
    {

        /// <summary>
        /// Gets the completion list.从Names表中获取name_string字段的列表用于自动完成功能
        /// </summary>
        /// <param name="prefixText">The prefix text.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        [WebMethod]
        public string[] GetCompletionList(string prefixText, int count)
        {
            var dataContext = new Models.cnpcDataContext();
            return dataContext.names
                .Where(n => n.name_string.StartsWith(prefixText))  
                .OrderBy(n =>n.name_string)
                .Take(count)
                .Select(n => n.name_string)
                .ToArray();
        }  
    }
}
